<html>
<head><meta charset="utf-8"><title>static appears twice in binary · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html">static appears twice in binary</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="158103423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158103423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158103423">(Feb 12 2019 at 09:18)</a>:</h4>
<p>I'm compiling the std unit tests for my target and a particular static ends up twice in the resulting binary, which is... bad</p>



<a name="158103439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158103439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158103439">(Feb 12 2019 at 09:19)</a>:</h4>
<p>from gdb:</p>
<div class="codehilite"><pre><span></span>File src/libstd/sys/sgx/abi/tls.rs:
static struct SyncBitset std::sys::sgx::abi::tls::TLS_KEY_IN_USE::h0f340495a814d6d4;
static struct SyncBitset std::sys::sgx::abi::tls::TLS_KEY_IN_USE::hddca68d75da9bb5c;
</pre></div>



<a name="158103451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158103451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158103451">(Feb 12 2019 at 09:19)</a>:</h4>
<p>how does this happen?</p>



<a name="158103746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158103746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158103746">(Feb 12 2019 at 09:25)</a>:</h4>
<p>IIRC libstd unit tests are the one case where you might end up with two versions of libstd, the normal one and the <code>cfg(test)</code> one, linked together</p>



<a name="158103777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158103777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158103777">(Feb 12 2019 at 09:26)</a>:</h4>
<p>std unit tests are not actually normal unit tests</p>



<a name="158103802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158103802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158103802">(Feb 12 2019 at 09:26)</a>:</h4>
<p>they are a separate crate</p>



<a name="158103812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158103812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158103812">(Feb 12 2019 at 09:26)</a>:</h4>
<p>with its root in <code>libstd/tests/lib.rs</code></p>



<a name="158103830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158103830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158103830">(Feb 12 2019 at 09:27)</a>:</h4>
<p>oh, hm, that's true for liballoc and libcore, anyway</p>



<a name="158103838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158103838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158103838">(Feb 12 2019 at 09:27)</a>:</h4>
<p>that file doesn't exist...</p>



<a name="158103840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158103840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158103840">(Feb 12 2019 at 09:27)</a>:</h4>
<p>seems like libstd also has tests "inside" the lib?</p>



<a name="158103846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158103846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158103846">(Feb 12 2019 at 09:27)</a>:</h4>
<p>weird, I thought these libs would all be organized the same way.</p>



<a name="158103910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158103910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158103910">(Feb 12 2019 at 09:28)</a>:</h4>
<p>so yeah seems like there is some really crazy magic at work here, and it doesn't seem unlikely that that can duplicate statics</p>



<a name="158103917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158103917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158103917">(Feb 12 2019 at 09:28)</a>:</h4>
<div class="codehilite"><pre><span></span>// During testing, this crate is not actually the &quot;real&quot; std library, but rather
// it links to the real std library, which was compiled from this same source
// code. So any lang items std defines are conditionally excluded (or else they
// would generate duplicate lang item errors), and any globals it defines are
// _not_ the globals used by &quot;real&quot; std. So this import, defined only during
// testing gives test-std access to real-std lang items and globals. See #2912
#[cfg(test)] extern crate std as realstd;
</pre></div>



<a name="158103943"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158103943" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158103943">(Feb 12 2019 at 09:29)</a>:</h4>
<p>ok... so shouldn't there be a macro_use on that extern crate as well?</p>



<a name="158104001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158104001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158104001">(Feb 12 2019 at 09:30)</a>:</h4>
<p>(I'm testing a build now with <code>#[cfg(not(test))] macro_rules! thread_local { ... }</code>)</p>



<a name="158104016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158104016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158104016">(Feb 12 2019 at 09:30)</a>:</h4>
<p>hm, maybe? no idea^^</p>



<a name="158104030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158104030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158104030">(Feb 12 2019 at 09:31)</a>:</h4>
<p>I dont think it matters which of the two macros you use though</p>



<a name="158104032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158104032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158104032">(Feb 12 2019 at 09:31)</a>:</h4>
<p>so I dont think that'll help</p>



<a name="158104040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158104040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158104040">(Feb 12 2019 at 09:31)</a>:</h4>
<p>not adding the static at all to the test build seems better, like what you did</p>



<a name="158108572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/static%20appears%20twice%20in%20binary/near/158108572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/static.20appears.20twice.20in.20binary.html#158108572">(Feb 12 2019 at 10:52)</a>:</h4>
<p>this appears to work actually</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>